from django.db import models


# Create your models here.
class Student(models.Model):
    SEX_CHOICES = (
        (0, '男'),
        (1, '女'),
    )
    name = models.CharField(max_length=100, verbose_name='名字')  # verbose_name ,在django管理后台使用
    age = models.IntegerField(null=True, blank=True, verbose_name='年龄')
    sex = models.IntegerField(null=True, blank=True, verbose_name='性别', choices=SEX_CHOICES)  # 选项
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    is_deleted = models.BooleanField(default=False, verbose_name='逻辑删除')  # 逻辑删除

    # 一对多联系（外键）
    classes = models.ForeignKey('Classes', on_delete=models.CASCADE, verbose_name='班级')

    # 逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_deleted = True
        # 保存
        self.save()


class Classes(models.Model):
    name = models.CharField(max_length=30, verbose_name='班级名字')
    slogan = models.TextField(null=True, blank=True, verbose_name='口号')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    is_deleted = models.BooleanField(default=False, verbose_name='逻辑删除')  # 逻辑删除

    # 逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_deleted = True
        # 保存
        self.save()

    def __str__(self):
        return self.name
